import 'package:merchants/models/app_config.dart';
import 'package:logger/logger.dart';

class AppServices {
  static bool _isInitialized = false;
  static String? _appVersion;
  static final Logger _logger = Logger();

  /// 轻量初始化：仅加载 .env（供其他类使用）并取得 app 版本号。
  static Future<void> initialize() async {
    if (_isInitialized) return;
    try {
      await AppConfig.init();
      _appVersion = await AppConfig.getAppVersion();
      _isInitialized = true;
      _logger.d('AppServices 初始化完成: appVersion=$_appVersion');
    } catch (e) {
      _logger.e('AppServices 初始化失败: $e');
      rethrow;
    }
  }

  static String get appVersion {
    if (!_isInitialized || _appVersion == null) {
      throw Exception('AppServices 未初始化');
    }
    return _appVersion!;
  }
}
